<template>
    <div class="venue">
        <!-- search -->
        <div class="search">
            <input class="searchInput" @focus="inputFocus" @blur="inputBlur" v-model="searchInput">
            <i class="search-icon" v-show="searchShow"></i>
            <span class="searchPlaceHolder" v-show="searchShow">搜索</span>
        </div>
        <mTitle :title="title"></mTitle>
        <scroll class="venue-container" :data="venueList" v-show="!searchInput">
            <div>
                <ul class="venue-item">
                    <router-link :to="'/venueDetail/'+item.id"  tag="li" class="venue-list" v-for="(item, index) in venueList" :key="index">
                        <div class="left">
                            <img v-lazy="item.coverimg" class="left-img" alt="" />
                        </div>
                        <div class="right">
                            <h4 class="right-title">{{item.venuename}}</h4>
                            <p class="right-address">{{item.address}}</p>
                            <p class="right-desc">{{item.content}}</p>
                        </div> 
                    </router-link>
                </ul> 
            </div>
            <!-- 请求数据loading -->
            <div class="loading-wrapper" v-show="!venueList.length">
                <loading></loading>
            </div>
        </scroll>
        <!-- 匹配搜索结果 -->
        <scroll class="venue-container" :data="list" v-show="list.length">
            <div>
                <ul class="venue-item">
                    <router-link :to="'/venueDetail/'+item.id"  tag="li" class="venue-list" v-for="(item, index) in list" :key="index">
                        <div class="left">
                            <img :src="item.coverimg" class="left-img" alt="" />
                        </div>
                        <div class="right">
                            <h4 class="right-title">{{item.venuename}}</h4>
                            <p class="right-address">{{item.address}}</p>
                            <p class="right-desc">{{item.content}}</p>
                        </div> 
                    </router-link>
                </ul> 
            </div>
        </scroll>
        <div class="no-result" v-show="!list.length && searchInput">暂无搜索结果</div>
    </div>
</template>

<script>
    import axios from 'axios'
    import MTitle from 'base/title/title'
    import Scroll from 'base/scroll/scroll'
    import Loading from 'base/loading/loading'
    export default {
        data () {
            return {
                searchShow: true,
                searchInput: "",
                venueList: [],
                list: [],
                title: "所有场馆",
                detailList: {}
            }
        },
        methods: {
            inputFocus () {
                this.searchShow = false
            },
            inputBlur () {
                if (this.searchInput === "") {
                    this.searchShow = true
                }
            },
            // 页面请求
            getVenueInfo () {
                axios.post('/api/index.php?g=Api&m=Ucenter&a=venuelist', {
                    openid: localStorage.getItem("openid"),
                    mid: localStorage.getItem("memberid")
                }).then((res) => {
                    // 请求成功
                    if (res.data.rescode === "0000") {
                        this.venueList = res.data.data
                    }
                }).catch(function (error) {
                    // 请求失败
                })
            }
        },
        watch: {
            searchInput () {
                this.list = []
                let result = []
                if(this.searchInput === "") {
                    result = []
                    this.list = []
                    return
                }
                for (let i in this.venueList) {
                    let value = this.venueList[i].venuename
                    if (value.indexOf(this.searchInput) > -1) {
                        result.push(i)
                    }
                }
                for(let k in result) {
                    this.list = this.list.concat(this.venueList[result[k]])
                }
            }
        },
        components: {MTitle,Loading,Scroll},
        created() {
            this.getVenueInfo()
        }
    }
</script>

<style lang="stylus" scoped>
    @import '~common/stylus/mixins.styl'
    
    .venue
        width: 100%
        height: 100%
        position: relative
        overflow: hidden
        .search
            width: 100%
            height: 44px
            background: #efeff4
            padding: 0 15px
            box-sizing: border-box
            -webkit-box-sizing: border-box
            position: relative
            overflow: hidden
            .searchInput
                width: 100%
                height: 32px
                background: #fff
                margin-top: 6px
                border: none
                border-radius: 0
                padding: 0 10px
                box-sizing: border-box
                -webkit-box-sizing: border-box
            .search-icon
                position: absolute
                background: url('./search-icon.png') no-repeat
                width: 13px
                height: 13px
                background-size: 100% 100%
                top: 16px
                left: 50%
                margin-left: -15px
            .searchPlaceHolder
                font-size: 14px
                color: #979797
                position: absolute
                top: 17px
                left: 51%
        .no-result
            padding: 0 15px
            line-height: 30px
            font-size: 16px
            color: #888
        .venue-title
            width: 100%
            height: 40px
            position: absolute
            top: 60px
            display: flex
            align-items: center
            line-height: 40px
            border-top: 1px solid #eee
            border-bottom: 1px solid #eee
            box-sizing: border-box
            .item
                flex: 1
                text-align: center
                background: #fff
                height: 100%
                width: 100%
                box-sizing: border-box
                &.active
                    background: #0094d4
                    color: #fff
        .no-result
            padding: 0 15px
            line-height: 30px
            font-size: 16px
            color: #888
        .venue-container
            position: absolute
            top: 86px
            background: #fff
            bottom: 0
            left: 0
            width: 100%
            padding: 0 15px
            box-sizing: border-box
            overflow: hidden
            .loading-wrapper
                position: absolute
                width: 100%
                top: 50%
                -webkit-transform: translateY(-50%)
                transform: translateY(-50%)
                z-index: 9
            .venue-item
                width: 100%
                .venue-list
                    width: 100%
                    height: 100px
                    border-bottom: 1px solid #eee
                    box-sizing: border-box
                    padding-top: 10px
                    display: flex
                    align-items: center
                    overflow: hidden
                    .left
                        width: 100px
                        flex: 0 0 100px
                        .left-img
                            width: 100%
                    .right
                        flex: 1
                        margin-left: 10px
                        overflow: hidden
                        .right-title
                            font-size: 16px
                            color: #000
                        .right-address
                            font-size: 14px
                            color: #959595
                            margin-top: 4px
                            ellipsis()
                        .right-desc
                            font-size: 12px
                            color: #d1d1d1
                            margin-top: 2px
                            line-height: 150%
</style>